/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.easoft.code.pos.data.pojos;

import com.easoft.code.pos.data.dao.ComposeEntity;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

/**
 *
 * @author Eliu
 */
@Entity
@Table(name = "documento_oper")
@NamedQueries({
    @NamedQuery(name = "DocumentoOper.findAll", query = "SELECT d FROM DocumentoOper d"),
    @NamedQuery(name = "DocumentoOper.findById", query = "SELECT d FROM DocumentoOper d WHERE d.id = :id"),
    @NamedQuery(name = "DocumentoOper.findBySerie", query = "SELECT d FROM DocumentoOper d WHERE d.serie = :serie"),
    @NamedQuery(name = "DocumentoOper.findByNumero", query = "SELECT d FROM DocumentoOper d WHERE d.numero = :numero"),
    @NamedQuery(name = "DocumentoOper.findByFecha", query = "SELECT d FROM DocumentoOper d WHERE d.fecha = :fecha"),
    @NamedQuery(name = "DocumentoOper.findByPersonaTipo", query = "SELECT d FROM DocumentoOper d WHERE d.personaTipo = :personaTipo"),
    @NamedQuery(name = "DocumentoOper.findByEstado", query = "SELECT d FROM DocumentoOper d WHERE d.estado = :estado"),
    @NamedQuery(name = "DocumentoOper.findByEfectivo", query = "SELECT d FROM DocumentoOper d WHERE d.efectivo = :efectivo"),
    @NamedQuery(name = "DocumentoOper.findByCheque", query = "SELECT d FROM DocumentoOper d WHERE d.cheque = :cheque"),
    @NamedQuery(name = "DocumentoOper.findByCredito", query = "SELECT d FROM DocumentoOper d WHERE d.credito = :credito"),
    @NamedQuery(name = "DocumentoOper.findByTarjeta", query = "SELECT d FROM DocumentoOper d WHERE d.tarjeta = :tarjeta"),
    @NamedQuery(name = "DocumentoOper.findByDescuento", query = "SELECT d FROM DocumentoOper d WHERE d.descuento = :descuento"),
    @NamedQuery(name = "DocumentoOper.findByTotal", query = "SELECT d FROM DocumentoOper d WHERE d.total = :total")})
public class DocumentoOper implements Serializable, ComposeEntity {

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "documentoMovId")
    @LazyCollection(LazyCollectionOption.FALSE)
    private Collection<MovimientoInv> movimientoInvCollection;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Column(name = "serie")
    private String serie;
    @Basic(optional = false)
    @Column(name = "numero")
    private Integer numero;
    @Basic(optional = false)
    @Column(name = "fecha")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fecha;
    @Basic(optional = false)
    @Column(name = "persona_tipo")
    private Integer personaTipo;
    @Basic(optional = false)
    @Column(name = "estado")
    private Integer estado;
    @Basic(optional = false)
    @Column(name = "efectivo")
    private Float efectivo;
    @Basic(optional = false)
    @Column(name = "cheque")
    private Float cheque;
    @Basic(optional = false)
    @Column(name = "credito")
    private Float credito;
    @Basic(optional = false)
    @Column(name = "tarjeta")
    private Float tarjeta;
    @Basic(optional = false)
    @Column(name = "descuento")
    private Float descuento;
    @Basic(optional = false)
    @Column(name = "total")
    private Float total;
    @JoinColumn(name = "docto_oper_tipo", referencedColumnName = "id")
    @ManyToOne(optional = false)    
    private DocumentoOperTipo doctoOperTipo;
    @JoinColumn(name = "persona_id", referencedColumnName = "codigo")
    @ManyToOne(optional = false, cascade = CascadeType.ALL)
    private Persona personaId;

    public DocumentoOper() {
        this.foreings = new LinkedList();
    }

    public DocumentoOper(Integer id) {
        this.foreings = new LinkedList();
        this.id = id;
    }

    public void setTipoPersonaFromBinder(String btnTxt) {
        this.personaTipo = btnTxt.equals("Cliente") ? 1 : 2;
    }

    public DocumentoOper(Integer id, String serie, Integer numero, Date fecha, Integer personaTipo, Integer estado, Float efectivo, Float cheque, Float credito, Float tarjeta, Float descuento, Float total) {
        this.foreings = new LinkedList();
        this.id = id;
        this.serie = serie;
        this.numero = numero;
        this.fecha = fecha;
        this.personaTipo = personaTipo;
        this.estado = estado;
        this.efectivo = efectivo;
        this.cheque = cheque;
        this.credito = credito;
        this.tarjeta = tarjeta;
        this.descuento = descuento;
        this.total = total;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getSerie() {
        return serie;
    }

    public void setSerie(String serie) {
        this.serie = serie;
    }

    public Integer getNumero() {
        return numero;
    }

    public void setNumero(Integer numero) {
        this.numero = numero;
    }

    public Date getFecha() {
        return fecha;
    }

    public void setFecha(Date fecha) {
        this.fecha = fecha;
    }

    public Integer getPersonaTipo() {
        return personaTipo;
    }

    public void setPersonaTipo(Integer personaTipo) {
        this.personaTipo = personaTipo;
    }

    public Integer getEstado() {
        return estado;
    }

    public void setEstado(Integer estado) {
        this.estado = estado;
    }

    public Float getEfectivo() {
        return efectivo;
    }

    public void setEfectivo(Float efectivo) {
        this.efectivo = efectivo;
    }

    public Float getCheque() {
        return cheque;
    }

    public void setCheque(Float cheque) {
        this.cheque = cheque;
    }

    public Float getCredito() {
        return credito;
    }

    public void setCredito(Float credito) {
        this.credito = credito;
    }

    public Float getTarjeta() {
        return tarjeta;
    }

    public void setTarjeta(Float tarjeta) {
        this.tarjeta = tarjeta;
    }

    public Float getDescuento() {
        return descuento;
    }

    public void setDescuento(Float descuento) {
        this.descuento = descuento;
    }

    public Float getTotal() {
        return total;
    }

    public void setTotal(Float total) {
        this.total = total;
    }

    public DocumentoOperTipo getDoctoOperTipo() {
        return doctoOperTipo;
    }

    public void setDoctoOperTipo(DocumentoOperTipo doctoOperTipo) {
        this.doctoOperTipo = doctoOperTipo;
    }

    public Persona getPersonaId() {
        return personaId;
    }

    public void setPersonaId(Persona personaId) {
        this.personaId = personaId;
    }

    @Override
    public int hashCode() {
        Integer hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof DocumentoOper)) {
            return false;
        }
        DocumentoOper other = (DocumentoOper) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.easoft.code.pos.data.pojos.DocumentoOper[ id=" + id + " ]";
    }

    public Collection<MovimientoInv> getMovimientoInvCollection() {
        return movimientoInvCollection;
    }

    public void setMovimientoInvCollection(Collection<MovimientoInv> movimientoInvCollection) {
        this.movimientoInvCollection = movimientoInvCollection;
    }

    @Transient
    private List foreings;

    @Override
    public List getForeingEntities() {
        return foreings;
    }

}
